#include "MarsPrecompile.h"

#include "MarsFileSysMgr.h"

//////////////////////////////////////////////////////////////////////////
using namespace Core;

FileSysMgr* FileSysMgr::ms_pFileSysMgr = 0;

void FileSysMgr::Destroy()
{
	SAFE_DELETE( ms_pFileSysMgr );
}

FileSysMgr::FileSysMgr()
{

}

FileSysMgr::~FileSysMgr()
{
	Shutdown();
}

bool FileSysMgr::Initialize()
{

	return true;
}

void FileSysMgr::Shutdown()
{

}

bool FileSysMgr::LoadFileContent( const std::string& filename, std::string& content )
{
	FILE *file = NULL;
	errno_t err = fopen_s( &file, filename.c_str(), "rb" );
	if ( err != 0 )
	{
		content = "";
		return false;
	}

	fseek( file, 0, SEEK_END );
	long size = ftell( file );
	fseek( file, 0, SEEK_SET );
	char* buffer = new char[ size + 1 ];
	buffer[ size ] = 0;
	if ( fread( buffer, 1, size, file ) == ( unsigned long )size )
		content = buffer;

	fclose( file );
	delete[] buffer;

	return true;
}
